# -*- coding: utf-8 -*-
import unittest
from selenium import webdriver
import time
import xlrd
from venv1.Public.readexcel import excel_action
from venv1.Public.xlsx_utils import XlsxUtils
from venv1.Page.loginPage import loginPage
from venv1.publicModule.login import login
from venv1.Page.menuPage import menuPage
from venv1.publicModule.inquery import inquery
from venv1.Page.customerInfoPage import customerInfoPage
from venv1.publicModule.newPaperModule.paperInfo import paperInfo
from venv1.publicModule.newPaperModule.productInfo import productInfo
from venv1.publicModule.newPaperModule.otherInfo import otherInfo
from selenium.webdriver.support.ui import WebDriverWait
import traceback

class NewPaper_Case(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.driver = webdriver.Chrome()
        time.sleep(2)
        self.driver.maximize_window()
        self.driver.get("http://10.22.26.74:8080/dist/index.html#/")
        self.loginPage = loginPage(self.driver)
        self.login = login(self.driver)
        self.menupage = menuPage(self.driver)
        self.customerinfopage = customerInfoPage(self.driver)
        self.inquery = inquery(self.driver)
        self.paperinfo = paperInfo(self.driver)
        self.productinfo = productInfo(self.driver)
        self.otherinfo = otherInfo(self.driver)
    #登录
    def test01(self):
        time.sleep(3)
        self.login.login("tracy.wang", "123456")
    #选择菜单
    def test02(self):
        time.sleep(5)
        self.menupage.inNewPaper().click()
    def test03(self):
        #读取iscan生成的单号
        filename = r"..\TestData\iscanData.xlsx"
        excelread = xlrd.open_workbook(filename)
        table = excelread.sheet_by_name('Sheet1')
        h =table.nrows
        rownumber = 1
        for i in range(2, h):
            rownumber = rownumber +1
            excel = excel_action()
            list_data =excel.read_excel_row(filename, 0, i)
            #分配任务
            # WebDriverWait(self.driver, 40, 0.5).until(lambda x: x.find_element_by_xpath(
            #     "//*[@id='app']/div/div[3]/div[1]/div/div/div[2]/div[1]/div[1]/div/div[2]/span/div[2]/input"))
            try:
                self.inquery.Assign_To(list_data[4])
                time.sleep(3)
                self.menupage.inNewPaper().click()
                time.sleep(2)
                self.customerinfopage.policyNo().send_keys(list_data[4])
                time.sleep(1)
                self.customerinfopage.check().click()
                time.sleep(3)
                self.customerinfopage.checkResult().click()
                time.sleep(4)
                windowin = self.driver.window_handles
                self.driver.switch_to.window(windowin[-1])
                ############客户信息#####################
                self.paperinfo.paperinfo(list_data)
                windowin = self.driver.window_handles
                self.driver.switch_to.window(windowin[-1])
                #############产品信息####################
                self.productinfo.productinfo(list_data)
                windowin = self.driver.window_handles
                self.driver.switch_to.window(windowin[-1])
                #############其他信息###################
                self.otherinfo.otherinfo(list_data, filename, rownumber)
                windowin = self.driver.window_handles
                self.driver.switch_to.window(windowin[-1])
            except Exception:
                traceback.print_exc()
                # self.driver.quit()
                time.sleep(1)
                NewPaper_Case.setUpClass()
                time.sleep(1)
                NewPaper_Case.test01(self)
                time.sleep(1)
                NewPaper_Case.test02(self)





